{%  extends 'base.html' %}
{% block title %}
    <a class="navbar-brand" href="#"> 岗位信息 </a>
{% endblock %}

{% block write %}
    {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
    <li>
    <a href="{{ url_for('post_add') }}" class="btn btn-simple btn-info btn-icon like" data-toggle="dropdown">
        添加岗位
    </a>
    </li>
    {% endif %}
{% endblock %}

{% block content %}
        <div class="content">
        <h4 class="title">岗位信息</h4>
        <div class="toolbar">

            <!--        Here you can write extra buttons/actions for the toolbar              -->
            <form method="post">
                查询方式
                <select name="info" required>
                    <option value="postID">岗位编号</option>
                    <option value="postname">岗位名称</option>
                </select>
                <input type="text" name="date" autocomplete="off" required>
                <input type="submit" name="submit" value="查询">
            </form>

        </div>
        {% if info == 'postID' or info == 'postname' %}
            <div class="material-datatables">
                <table id="datatables" class="table table-striped table-no-bordered table-hover"
                       style="width:100%;cellspacing:0">
                    <thead>
                    <tr>
						<th>岗位编号</th>
                        <th>岗位名称</th>
                        <th>类型</th>
						<th>编制</th>
                        <th class="disabled-sorting">操作</th>
                    </tr>
                    </thead>

                    <tbody>
                    <tr>
                        <td>{{ posts.postID }}</td>
                        <td>{{ posts.postname }}</td>
                        <td>{{ posts.posttype }}</td>
                        {% if posts.establishment == None  %}
                        <td></td>
                        {% else %}
                        <td>{{ posts.establishment }}</td>
                        {% endif %}

                        {% if current_user.has_role('Admin') or current_user.has_role('Root') %}
                        <td>
                            <form  method="post" action="{{ url_for('post_delete',postID=posts.postID) }}">
                                <a href="{{ url_for('post_alter',postID=posts.postID) }}"
                                   class="btn btn-simple btn-info btn-icon like">修改</a>
                                <input name="delete" type="submit" value="删除" onclick="return confirm('确认删除此岗位？')" class="btn btn-simple btn-danger btn-icon remove">
                            </form>
                        </td>
                        {% endif %}
                    </tr>
                    </tbody>

                </table>
            </div>
        {% else %}

                <div class="material-datatables">
                    <table id="datatables" class="table table-striped table-no-bordered table-hover"
                           style="width:100%;cellspacing:0">
                        <thead>
                        <tr>
                            <th>岗位编号</th>
                            <th>岗位名称</th>
                            <th>类型</th>
                            <th>编制</th>
                            <th class="disabled-sorting">操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for post in posts %}
                        <tr>
                            <td>{{ post.postID }}</td>
                            <td>{{ post.postname }}</td>
                            <td>{{ post.posttype }}</td>
                            {% if post.establishment == None  %}
                            <td></td>
                            {% else %}
							<td>{{ post.establishment }}</td>
                            {% endif %}

							{% if current_user.has_role('Admin') or current_user.has_role('Root') %}
                            <td>
                            <form  method="post" action="{{ url_for('post_delete',postID=post.postID) }}">
                                <a href="{{ url_for('post_alter',postID=post.postID) }}"
                                   class="btn btn-simple btn-info btn-icon like">修改</a>
                                <input name="delete" type="submit" value="删除" onclick="return confirm('确认删除此岗位？')" class="btn btn-simple btn-danger btn-icon remove">
                            </form>
                            </td>
							{% endif %}
                        </tr>
                        {% endfor %}
                        </tbody>

                    </table>
                </div>


        {% endif %}
    </div>
{% endblock %}